package com.myh.cc.coom.recommend.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.myh.cc.coom.recommend.bean.RecommendDetaislBean
import com.myh.cc.databinding.ItemSingerDetailsBinding
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/18.   ：
 */
class RecommendDetailsAdapter(bean: RecommendDetaislBean):  RecyclerView.Adapter<RecommendDetailsAdapter.VH>() {


    val bean = bean
    private var singers: String = ""

    var mListener: OnItemClickListener? = null

    override fun onBindViewHolder(holder: RecommendDetailsAdapter.VH, position: Int) {
        var  list = bean.data.list[position]

        singers = ""
        for (singer_name in list.singer)
            singers += singer_name.name + "/"
        // 可以使用使用 joinToString
        singers.substring(0,singers.length - 2)

        holder.binding.itemDetailsTvMusicName.text = list.songname
        holder.binding.itemDetailsTvAuthName.text = singers

        holder.binding.itemRelaSingerDetails.setOnClickListener{

            view ->
            mListener?.onClick(view,position)
        }

    }

    override fun getItemCount(): Int {
        return bean.data.list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecommendDetailsAdapter.VH {
        return RecommendDetailsAdapter.VH.create(LayoutInflater.from(parent.context),parent)
    }


    class VH(binding: ItemSingerDetailsBinding): RecyclerView.ViewHolder(binding.root) {

        val binding = binding

        companion object {

            fun create(inflater: LayoutInflater, parent: ViewGroup): RecommendDetailsAdapter.VH {

                val binding = ItemSingerDetailsBinding.inflate(inflater, parent, false)
                return RecommendDetailsAdapter.VH(binding)
            }


        }
    }

}